package UnitTests;

import junit.framework.Assert;

import org.junit.Before;
import org.junit.Test;

import RefactoringA1.src.Bank;
import RefactoringA1.src.CheckingAccount;

/**
 * @author Thomas
 *
 */
public class BankTest {

	/**
	 * A Bank Object for use in @Test methods.
	 */
	Bank myBank;
	
	/**
	 * A checking account number.
	 */
	int checkAccNum;
	
	/**
	 * The account number for a full banking package.
	 */
	int fullAccNum;
	
	
	/**
	 * @throws java.lang.Exception
	 */
	@Before
	public void setUp() throws Exception {
		myBank = new Bank("TestBank");
		checkAccNum = myBank.openSimpleCheckingAccount();
		fullAccNum = myBank.openFullPackage();
	}

	/**
	 * Test method for {@link RefactoringA1.src.Bank#Bank(java.lang.String)}.
	 * All fields of the Bank Class are private and there are no setters or getters.
	 * There is nothing to test in the constructor.
	 */
	@Test
	public void testBank() {
		Assert.assertTrue(myBank instanceof Bank);
	}

	/**
	 * Test method for {@link RefactoringA1.src.Bank#openSimpleCheckingAccount()}.
	 * Verifies that the account number is 0, which means that it is the first checking
	 * account created on the myBank Object.
	 */
	@Test
	public void testOpenSimpleCheckingAccount() {
		final Bank bank = new Bank("Bank");
		final int accNum = bank.openSimpleCheckingAccount();
		Assert.assertTrue(accNum > 0);
	}

	/**
	 * Test method for {@link RefactoringA1.src.Bank#openFullPackage()}.
	 */
	@Test
	public void testOpenFullPackage() {
		final CheckingAccount ca = new CheckingAccount(fullAccNum);
		Assert.assertEquals(ca.getAccountNumber(), fullAccNum);
	}

	/**
	 * Test method for {@link RefactoringA1.src.Bank#withdrawMoney(int, double)}.
	 */
	@Test
	public void testWithdrawMoney() {
		Assert.assertEquals(false, myBank.withdrawMoney(fullAccNum, 1.00));
	}

	/**
	 * Test method for {@link java.lang.Object#Object()}.
	 */
	@Test
	public void testObject() {
		Assert.assertTrue(myBank instanceof Bank);
	}

	/**
	 * Test method for {@link java.lang.Object#getClass()}.
	 */
	@Test
	public void testGetClass() {
		Assert.assertTrue(myBank.getClass().getSimpleName().equals("Bank"));
	}

	/**
	 * Test method for {@link java.lang.Object#equals(java.lang.Object)}.
	 */
	@Test
	public void testEquals() {
		final Bank otherBank = new Bank("OtherBank");
		Assert.assertFalse(myBank.equals(otherBank));
		Assert.assertEquals(myBank, myBank);
	}
}
